export const state = () => ({
  user: "", // 登录的用户
  showLogin: false // 用于控制是否显示登录组件
})

export const mutations = {
  // 不要在mutations中写异步操作
  setUser(state, data) {
    // console.log("setUser mutations", state, data)
    state.user = data;
    // console.log("setUser mutations state.user", JSON.stringify(state.user), "end")
  }, setShowLogin(state, data) {
    state.showLogin = data;
  }
}

export const actions = {
  // 执行异步操作 actions 执行
  setUser({commit}, data) {
    console.log("setUser actions", state, data)
    commit('setUser', data);
  }, setShowLogin({commit}, data) {
    commit('setShowLogin', data);
  }
}

export const getters = {
  getUser(state) {
    return state.user
  }, getUserName(state) {
    return state.user.userName
  }, getShowLogin(state) {
    return state.showLogin
  },getUserPid(state) {
    return state.user.pid
  }
}
